﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SklepISI.Core;
using SklepISI.Core.Models;
using SklepISI.Core.Services;

namespace SklepISI.Console
{
    class Program
    {
        private static UserService _userService;

        static void Main(string[] args)
        {
            Bootstrapper.Initialize();
            _userService = new UserService();
            CheckChangePassword();
            _userService.CreateUser(new UserModel()
                                   {
                                       RoleId = 1,
                                       Address = "Address",
                                       Email = "mail@mail.com",
                                       FirstName = "Zygmunt",
                                       LastName = "Pierdzimąka",
                                       Password = "admin",
                                       PostalCode = "01-001",
                                       Username = "admin"
                                   }); ///// OK

            var validResult = _userService.ValidUser("admin", "admin");
            Debug.Assert(validResult);

            var orderService = new OrderService();
            //orderService.CreateOrder(new NewOrderModel()
            //                             {
            //                                 UserId = 1,
            //                                 DeliveryAddress = "czwarty karton od lewej",
            //                                 Products = new List<NewOrderProductModel>()
            //                                                {
            //                                                    new NewOrderProductModel()
            //                                                        {
            //                                                            ProductId = 2,
            //                                                            ProductPrice = 12M,
            //                                                            Quantity = 2
            //                                                        },
            //                                                    new NewOrderProductModel()
            //                                                        {
            //                                                            ProductId = 3,
            //                                                            ProductPrice = 15M,
            //                                                            Quantity = 300
            //                                                        }
            //                                                }
            //                             }); //////OK

            //_userService.RemoveUser("user12312321232");

        }

        static void CheckChangePassword()
        {
            const string startPassword = "startPassword";
            const string endPassword = "endPassword";
            var newUser = new UserModel()
                                    {
                                        Address = "Karton",
                                        FirstName = "Ferdek",
                                        Email = "mail2@mail.com",
                                        LastName = "LastName",
                                        Password = startPassword,
                                        PostalCode = "02-002",
                                        Username = "testUser",
                                        RoleId = 1
                                    };

            _userService.CreateUser(newUser);
            var result = _userService.ChangePassword(newUser.Username, startPassword, endPassword);
            if (result)
            {
                System.Console.WriteLine("change password OK !");
                _userService.ChangePassword(newUser.Username, endPassword, startPassword); //revert
            }
            else
            {
                System.Console.WriteLine("change password Fail !");
                Debugger.Break();
            }
        }
    }
}
